package com.itheima.behavior.controller.v1;

import com.itheima.behavior.service.CollectService;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.utils.thread.MpThreadLocalUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户收藏控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/collect")
@Api(tags = "用户收藏相关接口")
public class CollectController {

    @Autowired
    private CollectService collectService;

    /**
     * 收藏图书
     */
    @PostMapping("/book/{id}")
    @ApiOperation("收藏图书")
    public ResponseResult collectBook(
            @ApiParam("图书ID") @PathVariable Integer id) {
        return collectService.collectBook(id);
    }

    /**
     * 取消收藏图书
     */
    @DeleteMapping("/book/{id}")
    @ApiOperation("取消收藏图书")
    public ResponseResult cancelCollectBook(
            @ApiParam("图书ID") @PathVariable Integer id) {
        return collectService.cancelCollectBook(id);
    }

    /**
     * 收藏笔记
     */
    @PostMapping("/note/{id}")
    @ApiOperation("收藏笔记")
    public ResponseResult collectNote(
            @ApiParam("笔记ID") @PathVariable String id) {
        return collectService.collectNote(id);
    }

    /**
     * 取消收藏笔记
     */
    @DeleteMapping("/note/{id}")
    @ApiOperation("取消收藏笔记")
    public ResponseResult cancelCollectNote(
            @ApiParam("笔记ID") @PathVariable String id) {
        return collectService.cancelCollectNote(id);
    }

    /**
     * 收藏书评
     */
    @PostMapping("/review/{id}")
    @ApiOperation("收藏书评")
    public ResponseResult collectReview(
            @ApiParam("书评ID") @PathVariable String id) {
        return collectService.collectReview(id);
    }

    /**
     * 取消收藏书评
     */
    @DeleteMapping("/review/{id}")
    @ApiOperation("取消收藏书评")
    public ResponseResult cancelCollectReview(
            @ApiParam("书评ID") @PathVariable String id) {
        return collectService.cancelCollectReview(id);
    }

    /**
     * 获取用户收藏列表
     */
    @GetMapping("/list")
    @ApiOperation("获取用户收藏列表")
    public ResponseResult getUserCollections() {
        return collectService.getUserCollections();
    }
}